package com.sishuok.jmstest.topic;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;

public class PersistenceSender {
	public static void main(String[] args) throws Exception {
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://172.16.15.111:61616");
		Connection connection = connectionFactory.createConnection();
		
		Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		Topic destination = session.createTopic("VirtualTopic.MyTopic");//("my-topic");
		MessageProducer producer = session.createProducer(destination);
		producer.setDeliveryMode(DeliveryMode.PERSISTENT);//持久化订阅
		connection.start();//在设置完成后再start
		
		for(int i=0;i<3;i++){
			TextMessage message = session.createTextMessage("message66--"+i);
			producer.send(message);
		}
		session.commit();
		session.close();
		connection.close();
	}
}
